home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / perl / sprite / a2p.h < prev    next >
Encoding:
C/C++ Source or Header  |  1991-11-14  |  6.3 KB  |  343 lines

  1. /* $RCSfile: a2p.h,v $$Revision: 1.3 $$Date: 91/11/14 12:50:57 $
  2.  *
  3.  *    Copyright (c) 1991, Larry Wall
  4.  *
  5.  *    You may distribute under the terms of either the GNU General Public
  6.  *    License or the Artistic License, as specified in the README file.
  7.  *
  8.  * $Log:    a2p.h,v $
  9.  * Revision 1.3  91/11/14  12:50:57  jhh
  10.  * finally got the include of config.h set up properly
  11.  * 
  12.  * Revision 1.2  91/08/12  16:41:45  jhh
  13.  * config.h is in a different place
  14.  * 
  15.  * Revision 1.1  91/07/16  17:18:13  jhh
  16.  * Initial revision
  17.  * 
  18.  * Revision 4.0.1.1  91/06/07  12:12:27  lwall
  19.  * patch4: new copyright notice
  20.  * 
  21.  * Revision 4.0  91/03/20  01:57:07  lwall
  22.  * 4.0 baseline.
  23.  * 
  24.  */
  25.  
  26. #define VOIDUSED 1
  27. #include "config.h"
  28.  
  29. #ifndef HAS_BCOPY
  30. #   define bcopy(s1,s2,l) memcpy(s2,s1,l)
  31. #endif
  32. #ifndef HAS_BZERO
  33. #   define bzero(s,l) memset(s,0,l)
  34. #endif
  35.  
  36. #include "handy.h"
  37. #define Nullop 0
  38.  
  39. #define OPROG        1
  40. #define OJUNK        2
  41. #define OHUNKS        3
  42. #define ORANGE        4
  43. #define OPAT        5
  44. #define OHUNK        6
  45. #define OPPAREN        7
  46. #define OPANDAND    8
  47. #define OPOROR        9
  48. #define OPNOT        10
  49. #define OCPAREN        11
  50. #define OCANDAND    12
  51. #define OCOROR        13
  52. #define OCNOT        14
  53. #define ORELOP        15
  54. #define ORPAREN        16
  55. #define OMATCHOP    17
  56. #define OMPAREN        18
  57. #define OCONCAT        19
  58. #define OASSIGN        20
  59. #define OADD        21
  60. #define OSUBTRACT    22
  61. #define OMULT        23
  62. #define ODIV        24
  63. #define OMOD        25
  64. #define OPOSTINCR    26
  65. #define OPOSTDECR    27
  66. #define OPREINCR    28
  67. #define OPREDECR    29
  68. #define OUMINUS        30
  69. #define OUPLUS        31
  70. #define OPAREN        32
  71. #define OGETLINE    33
  72. #define OSPRINTF    34
  73. #define OSUBSTR        35
  74. #define OSTRING        36
  75. #define OSPLIT        37
  76. #define OSNEWLINE    38
  77. #define OINDEX        39
  78. #define ONUM        40
  79. #define OSTR        41
  80. #define OVAR        42
  81. #define OFLD        43
  82. #define ONEWLINE    44
  83. #define OCOMMENT    45
  84. #define OCOMMA        46
  85. #define OSEMICOLON    47
  86. #define OSCOMMENT    48
  87. #define OSTATES        49
  88. #define OSTATE        50
  89. #define OPRINT        51
  90. #define OPRINTF        52
  91. #define OBREAK        53
  92. #define ONEXT        54
  93. #define OEXIT        55
  94. #define OCONTINUE    56
  95. #define OREDIR        57
  96. #define OIF        58
  97. #define OWHILE        59
  98. #define OFOR        60
  99. #define OFORIN        61
  100. #define OVFLD        62
  101. #define OBLOCK        63
  102. #define OREGEX        64
  103. #define OLENGTH        65
  104. #define OLOG        66
  105. #define OEXP        67
  106. #define OSQRT        68
  107. #define OINT        69
  108. #define ODO        70
  109. #define OPOW        71
  110. #define OSUB        72
  111. #define OGSUB        73
  112. #define OMATCH        74
  113. #define OUSERFUN    75
  114. #define OUSERDEF    76
  115. #define OCLOSE        77
  116. #define OATAN2        78
  117. #define OSIN        79
  118. #define OCOS        80
  119. #define ORAND        81
  120. #define OSRAND        82
  121. #define ODELETE        83
  122. #define OSYSTEM        84
  123. #define OCOND        85
  124. #define ORETURN        86
  125. #define ODEFINED    87
  126. #define OSTAR        88
  127.  
  128. #ifdef DOINIT
  129. char *opname[] = {
  130.     "0",
  131.     "PROG",
  132.     "JUNK",
  133.     "HUNKS",
  134.     "RANGE",
  135.     "PAT",
  136.     "HUNK",
  137.     "PPAREN",
  138.     "PANDAND",
  139.     "POROR",
  140.     "PNOT",
  141.     "CPAREN",
  142.     "CANDAND",
  143.     "COROR",
  144.     "CNOT",
  145.     "RELOP",
  146.     "RPAREN",
  147.     "MATCHOP",
  148.     "MPAREN",
  149.     "CONCAT",
  150.     "ASSIGN",
  151.     "ADD",
  152.     "SUBTRACT",
  153.     "MULT",
  154.     "DIV",
  155.     "MOD",
  156.     "POSTINCR",
  157.     "POSTDECR",
  158.     "PREINCR",
  159.     "PREDECR",
  160.     "UMINUS",
  161.     "UPLUS",
  162.     "PAREN",
  163.     "GETLINE",
  164.     "SPRINTF",
  165.     "SUBSTR",
  166.     "STRING",
  167.     "SPLIT",
  168.     "SNEWLINE",
  169.     "INDEX",
  170.     "NUM",
  171.     "STR",
  172.     "VAR",
  173.     "FLD",
  174.     "NEWLINE",
  175.     "COMMENT",
  176.     "COMMA",
  177.     "SEMICOLON",
  178.     "SCOMMENT",
  179.     "STATES",
  180.     "STATE",
  181.     "PRINT",
  182.     "PRINTF",
  183.     "BREAK",
  184.     "NEXT",
  185.     "EXIT",
  186.     "CONTINUE",
  187.     "REDIR",
  188.     "IF",
  189.     "WHILE",
  190.     "FOR",
  191.     "FORIN",
  192.     "VFLD",
  193.     "BLOCK",
  194.     "REGEX",
  195.     "LENGTH",
  196.     "LOG",
  197.     "EXP",
  198.     "SQRT",
  199.     "INT",
  200.     "DO",
  201.     "POW",
  202.     "SUB",
  203.     "GSUB",
  204.     "MATCH",
  205.     "USERFUN",
  206.     "USERDEF",
  207.     "CLOSE",
  208.     "ATAN2",
  209.     "SIN",
  210.     "COS",
  211.     "RAND",
  212.     "SRAND",
  213.     "DELETE",
  214.     "SYSTEM",
  215.     "COND",
  216.     "RETURN",
  217.     "DEFINED",
  218.     "STAR",
  219.     "89"
  220. };
  221. #else
  222. extern char *opname[];
  223. #endif
  224.  
  225. EXT int mop INIT(1);
  226.  
  227. union u_ops {
  228.     int ival;
  229.     char *cval;
  230. };
  231. #if defined(iAPX286) || defined(M_I286) || defined(I80286)     /* 80286 hack */
  232. #define OPSMAX (64000/sizeof(union u_ops))    /* approx. max segment size */
  233. #else
  234. #define OPSMAX 50000
  235. #endif                             /* 80286 hack */
  236. union u_ops ops[OPSMAX];
  237.  
  238. #include <stdio.h>
  239. #include <ctype.h>
  240.  
  241. typedef struct string STR;
  242. typedef struct htbl HASH;
  243.  
  244. #include "str.h"
  245. #include "hash.h"
  246.  
  247. /* A string is TRUE if not "" or "0". */
  248. #define True(val) (tmps = (val), (*tmps && !(*tmps == '0' && !tmps[1])))
  249. EXT char *Yes INIT("1");
  250. EXT char *No INIT("");
  251.  
  252. #define str_true(str) (Str = (str), (Str->str_pok ? True(Str->str_ptr) : (Str->str_nok ? (Str->str_nval != 0.0) : 0 )))
  253.  
  254. #define str_peek(str) (Str = (str), (Str->str_pok ? Str->str_ptr : (Str->str_nok ? (sprintf(buf,"num(%g)",Str->str_nval),buf) : "" )))
  255. #define str_get(str) (Str = (str), (Str->str_pok ? Str->str_ptr : str_2ptr(Str)))
  256. #define str_gnum(str) (Str = (str), (Str->str_nok ? Str->str_nval : str_2num(Str)))
  257. EXT STR *Str;
  258.  
  259. #define GROWSTR(pp,lp,len) if (*(lp) < (len)) growstr(pp,lp,len)
  260.  
  261. STR *str_new();
  262.  
  263. char *scanpat();
  264. char *scannum();
  265.  
  266. void str_free();
  267.  
  268. EXT int line INIT(0);
  269.  
  270. EXT FILE *rsfp;
  271. EXT char buf[2048];
  272. EXT char *bufptr INIT(buf);
  273.  
  274. EXT STR *linestr INIT(Nullstr);
  275.  
  276. EXT char tokenbuf[2048];
  277. EXT int expectterm INIT(TRUE);
  278.  
  279. #ifdef DEBUGGING
  280. EXT int debug INIT(0);
  281. EXT int dlevel INIT(0);
  282. #define YYDEBUG 1
  283. extern int yydebug;
  284. #endif
  285.  
  286. EXT STR *freestrroot INIT(Nullstr);
  287.  
  288. EXT STR str_no;
  289. EXT STR str_yes;
  290.  
  291. EXT bool do_split INIT(FALSE);
  292. EXT bool split_to_array INIT(FALSE);
  293. EXT bool set_array_base INIT(FALSE);
  294. EXT bool saw_RS INIT(FALSE);
  295. EXT bool saw_OFS INIT(FALSE);
  296. EXT bool saw_ORS INIT(FALSE);
  297. EXT bool saw_line_op INIT(FALSE);
  298. EXT bool in_begin INIT(TRUE);
  299. EXT bool do_opens INIT(FALSE);
  300. EXT bool do_fancy_opens INIT(FALSE);
  301. EXT bool lval_field INIT(FALSE);
  302. EXT bool do_chop INIT(FALSE);
  303. EXT bool need_entire INIT(FALSE);
  304. EXT bool absmaxfld INIT(FALSE);
  305. EXT bool saw_altinput INIT(FALSE);
  306.  
  307. EXT char const_FS INIT(0);
  308. EXT char *namelist INIT(Nullch);
  309. EXT char fswitch INIT(0);
  310.  
  311. EXT int saw_FS INIT(0);
  312. EXT int maxfld INIT(0);
  313. EXT int arymax INIT(0);
  314. char *nameary[100];
  315.  
  316. EXT STR *opens;
  317.  
  318. EXT HASH *symtab;
  319. EXT HASH *curarghash;
  320.  
  321. #define P_MIN        0
  322. #define P_LISTOP    5
  323. #define P_COMMA        10
  324. #define P_ASSIGN    15
  325. #define P_COND        20
  326. #define P_DOTDOT    25
  327. #define P_OROR        30
  328. #define P_ANDAND    35
  329. #define P_OR        40
  330. #define P_AND        45
  331. #define P_EQ        50
  332. #define P_REL        55
  333. #define P_UNI        60
  334. #define P_FILETEST    65
  335. #define P_SHIFT        70
  336. #define P_ADD        75
  337. #define P_MUL        80
  338. #define P_MATCH        85
  339. #define P_UNARY        90
  340. #define P_POW        95
  341. #define P_AUTO        100
  342. #define P_MAX        999
  343.